1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.GridView;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.ListBase;
31 private import gtk.ListItemFactory;
32 private import gtk.SelectionModelIF;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 private import std.algorithm;
37 
38 
39 /**
40  * `GtkGridView` presents a large dynamic grid of items.
41  * 
42  * `GtkGridView` uses its factory to generate one child widget for each
43  * visible item and shows them in a grid. The orientation of the grid view
44  * determines if the grid reflows vertically or horizontally.
45  * 
46  * `GtkGridView` allows the user to select items according to the selection
47  * characteristics of the model. For models that allow multiple selected items,
48  * it is possible to turn on _rubberband selection_, using
49  * [property@Gtk.GridView:enable-rubberband].
50  * 
51  * To learn more about the list widget framework, see the
52  * [overview](section-list-widget.html).
53  * 
54  * # CSS nodes
55  * 
56  * ```
57  * gridview
58  * ├── child[.activatable]
59  * │
60  * ├── child[.activatable]
61  * │
62  * ┊
63  * ╰── [rubberband]
64  * ```
65  * 
66  * `GtkGridView` uses a single CSS node with name `gridview`. Each child uses
67  * a single CSS node with name `child`. If the [property@Gtk.ListItem:activatable]
68  * property is set, the corresponding row will have the `.activatable` style
69  * class. For rubberband selection, a subnode with name `rubberband` is used.
70  * 
71  * # Accessibility
72  * 
73  * `GtkGridView` uses the %GTK_ACCESSIBLE_ROLE_GRID role, and the items
74  * use the %GTK_ACCESSIBLE_ROLE_GRID_CELL role.
75  */
76 public class GridView : ListBase
77 {
78 	/** the main Gtk struct */
79 	protected GtkGridView* gtkGridView;
80 
81 	/** Get the main Gtk struct */
82 	public GtkGridView* getGridViewStruct(bool transferOwnership = false)
83 	{
84 		if (transferOwnership)
85 			ownedRef = false;
86 		return gtkGridView;
87 	}
88 
89 	/** the main Gtk struct as a void* */
90 	protected override void* getStruct()
91 	{
92 		return cast(void*)gtkGridView;
93 	}
94 
95 	/**
96 	 * Sets our main struct and passes it to the parent class.
97 	 */
98 	public this (GtkGridView* gtkGridView, bool ownedRef = false)
99 	{
100 		this.gtkGridView = gtkGridView;
101 		super(cast(GtkListBase*)gtkGridView, ownedRef);
102 	}
103 
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return gtk_grid_view_get_type();
109 	}
110 
111 	/**
112 	 * Creates a new `GtkGridView` that uses the given @factory for
113 	 * mapping items to widgets.
114 	 *
115 	 * The function takes ownership of the
116 	 * arguments, so you can write code like
117 	 * ```c
118 	 * grid_view = gtk_grid_view_new (create_model (),
119 	 * gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
120 	 * ```
121 	 *
122 	 * Params:
123 	 *     model = the model to use
124 	 *     factory = The factory to populate items with
125 	 *
126 	 * Returns: a new `GtkGridView` using the given @model and @factory
127 	 *
128 	 * Throws: ConstructionException GTK+ fails to create the object.
129 	 */
130 	public this(SelectionModelIF model, ListItemFactory factory)
131 	{
132 		auto __p = gtk_grid_view_new((model is null) ? null : model.getSelectionModelStruct(), (factory is null) ? null : factory.getListItemFactoryStruct());
133 
134 		if(__p is null)
135 		{
136 			throw new ConstructionException("null returned by new");
137 		}
138 
139 		this(cast(GtkGridView*) __p);
140 	}
141 
142 	/**
143 	 * Returns whether rows can be selected by dragging with the mouse.
144 	 *
145 	 * Returns: %TRUE if rubberband selection is enabled
146 	 */
147 	public bool getEnableRubberband()
148 	{
149 		return gtk_grid_view_get_enable_rubberband(gtkGridView) != 0;
150 	}
151 
152 	/**
153 	 * Gets the factory that's currently used to populate list items.
154 	 *
155 	 * Returns: The factory in use
156 	 */
157 	public ListItemFactory getFactory()
158 	{
159 		auto __p = gtk_grid_view_get_factory(gtkGridView);
160 
161 		if(__p is null)
162 		{
163 			return null;
164 		}
165 
166 		return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p);
167 	}
168 
169 	/**
170 	 * Gets the maximum number of columns that the grid will use.
171 	 *
172 	 * Returns: The maximum number of columns
173 	 */
174 	public uint getMaxColumns()
175 	{
176 		return gtk_grid_view_get_max_columns(gtkGridView);
177 	}
178 
179 	/**
180 	 * Gets the minimum number of columns that the grid will use.
181 	 *
182 	 * Returns: The minimum number of columns
183 	 */
184 	public uint getMinColumns()
185 	{
186 		return gtk_grid_view_get_min_columns(gtkGridView);
187 	}
188 
189 	/**
190 	 * Gets the model that's currently used to read the items displayed.
191 	 *
192 	 * Returns: The model in use
193 	 */
194 	public SelectionModelIF getModel()
195 	{
196 		auto __p = gtk_grid_view_get_model(gtkGridView);
197 
198 		if(__p is null)
199 		{
200 			return null;
201 		}
202 
203 		return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p);
204 	}
205 
206 	/**
207 	 * Returns whether items will be activated on single click and
208 	 * selected on hover.
209 	 *
210 	 * Returns: %TRUE if items are activated on single click
211 	 */
212 	public bool getSingleClickActivate()
213 	{
214 		return gtk_grid_view_get_single_click_activate(gtkGridView) != 0;
215 	}
216 
217 	/**
218 	 * Sets whether selections can be changed by dragging with the mouse.
219 	 *
220 	 * Params:
221 	 *     enableRubberband = %TRUE to enable rubberband selection
222 	 */
223 	public void setEnableRubberband(bool enableRubberband)
224 	{
225 		gtk_grid_view_set_enable_rubberband(gtkGridView, enableRubberband);
226 	}
227 
228 	/**
229 	 * Sets the `GtkListItemFactory` to use for populating list items.
230 	 *
231 	 * Params:
232 	 *     factory = the factory to use
233 	 */
234 	public void setFactory(ListItemFactory factory)
235 	{
236 		gtk_grid_view_set_factory(gtkGridView, (factory is null) ? null : factory.getListItemFactoryStruct());
237 	}
238 
239 	/**
240 	 * Sets the maximum number of columns to use.
241 	 *
242 	 * This number must be at least 1.
243 	 *
244 	 * If @max_columns is smaller than the minimum set via
245 	 * [method@Gtk.GridView.set_min_columns], that value is used instead.
246 	 *
247 	 * Params:
248 	 *     maxColumns = The maximum number of columns
249 	 */
250 	public void setMaxColumns(uint maxColumns)
251 	{
252 		gtk_grid_view_set_max_columns(gtkGridView, maxColumns);
253 	}
254 
255 	/**
256 	 * Sets the minimum number of columns to use.
257 	 *
258 	 * This number must be at least 1.
259 	 *
260 	 * If @min_columns is smaller than the minimum set via
261 	 * [method@Gtk.GridView.set_max_columns], that value is ignored.
262 	 *
263 	 * Params:
264 	 *     minColumns = The minimum number of columns
265 	 */
266 	public void setMinColumns(uint minColumns)
267 	{
268 		gtk_grid_view_set_min_columns(gtkGridView, minColumns);
269 	}
270 
271 	/**
272 	 * Sets the imodel to use.
273 	 *
274 	 * This must be a [iface@Gtk.SelectionModel].
275 	 *
276 	 * Params:
277 	 *     model = the model to use
278 	 */
279 	public void setModel(SelectionModelIF model)
280 	{
281 		gtk_grid_view_set_model(gtkGridView, (model is null) ? null : model.getSelectionModelStruct());
282 	}
283 
284 	/**
285 	 * Sets whether items should be activated on single click and
286 	 * selected on hover.
287 	 *
288 	 * Params:
289 	 *     singleClickActivate = %TRUE to activate items on single click
290 	 */
291 	public void setSingleClickActivate(bool singleClickActivate)
292 	{
293 		gtk_grid_view_set_single_click_activate(gtkGridView, singleClickActivate);
294 	}
295 
296 	/**
297 	 * Emitted when a cell has been activated by the user,
298 	 * usually via activating the GtkGridView|list.activate-item action.
299 	 *
300 	 * This allows for a convenient way to handle activation in a gridview.
301 	 * See [property@Gtk.ListItem:activatable] for details on how to use
302 	 * this signal.
303 	 *
304 	 * Params:
305 	 *     position = position of item to activate
306 	 */
307 	gulong addOnActivate(void delegate(uint, GridView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
308 	{
309 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
310 	}
311 }